package adpater;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;
import java.util.List;

import entity.Animation;

public class ImagerPagerAdapter extends PagerAdapter {

    private Context context;
    private List<Animation> AimInfo;
    private List<ImageView> imageViews = new ArrayList<>();

    public ImagerPagerAdapter(Context context, List<Animation> aimInfo) {
        this.context = context;
        AimInfo = aimInfo;

        for (Animation info : aimInfo) {
            ImageView imageView = new ImageView(context);
            imageView.setImageResource(info.getPic());
            imageViews.add(imageView);
        }
    }

    @Override
    public int getCount() {
        return AimInfo.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) { // initial
        ImageView imageView = imageViews.get(position);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(imageViews.get(position));
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return AimInfo.get(position).getTitle();
    }
}
